---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  1_SingleWomen_ReadInCps.log
  log type:  text
 opened on:  13 Apr 2018, 11:33:24

. ***************************************************************************;
. * READ IN CPS DATA FROM IPUMS FOR EITC EMPLOYMENT PROJECT ;
. ***************************************************************************;
. local beginTime "DateTime: $S_DATE $S_TIME";

. set more off ;

. set linesize 200 ;

. set mem 5g ;
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. cd "$dataDir" ;


.         ***************************************************************************;
. * DEFINE STUFF THAT WE DONT EVER WANT TO COMMENT OUT. ;
. ***************************************************************************;
. local technical_vars "year serial relate famunit pernum wtsupp spmwt hwtsupp";

. local demographic_vars "age marst race sex hispan educ
>         statefip wkswork1 uhrswork wksunem1 whynwly mthwelfr schlcoll
>         nfams nmothers momloc momrule poploc poprule foodstmp
>         pubhous rentsub heatsub lunchsub offtotval stampval heatval union
>         qincwage poverty offcutoff offpov spmpov spmthresh spmtotres spmeitc 
>         spmfedtaxac spmfedtaxbc" ;

. local income_vars "inctot incwage incbus incfarm incss incwelfr incgov 
>         incaloth incretir incssi incdrt incint incunemp incwkcom incvet incsurv 
>         incdisab incdivid incrent inceduc incchild incalim incasist incother  ";

. ***************************************************************************;
. * READ IN IPUMS CPS DATA ;
. ***************************************************************************;
. * A LIST OF VARIABLES WE WANT TO KEEP FROM THE DATA ;
. local keepList "`technical_vars' `demographic_vars' `income_vars'" ;

. local cps "cps_00017";

. capture erase `cps'.do ;

. capture erase `cps'.dat ;

. capture erase `cps'.dat.gz ;

. local from "$rawDir\\`cps'.dat.gz" ;

. local to "$dataDir\\`cps'.dat.gz"  ;

. copy `from' `to' , replace;

. shell 7za e `cps'.dat.gz ;

. local from "$rawDir\\`cps'.do" ;

. local to "$dataDir\\`cps'.do"  ;

. copy `from' `to' , replace;

. quietly do `cps'.do ;

. keep `keepList' ;

. * SET MISSINGS TO ZERO - TOPCODING, MISSING VALUES ETC IS NOT AS CLEAR AS ;
. * DESCRIBED IN THE DOCUMENTATION, ONE REALLY HAS TO LOOK AT THE DATA AND SEE ;
. foreach var of varlist `income_vars' {;
  2.         qui replace `var' = . if (`var' == -19998 | `var' == -9999 | 
>                 `var' == 9999 | `var' == 99997 | `var' == 99998 | `var' == 99999 | 
>                 `var' == 999997 | `var' == 9999997 | `var' == 999999 | 
>                 `var' == 99999997 | `var' >= 9999999 | `var' == 1099999 | `var'>1000000 |
>                 inctot == .);
  3.         };

.         foreach var of varlist `income_vars' {;
  2.         qui replace `var' = 0 if `var' == . ;
  3.         };

. summ `income_vars'  ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      inctot |  6,076,183     18034.8    32218.48     -29647    1000000
     incwage |  6,076,183    13679.27     29122.8          0    1000000
      incbus |  6,076,183    872.9827    8870.666     -19882     850000
     incfarm |  6,076,183    100.2237    3019.219     -16000     550000
       incss |  6,076,183    1056.231    3390.951          0      50000
-------------+---------------------------------------------------------
    incwelfr |  6,076,183    41.14476     464.745          0      25000
      incgov |  6,076,183    26.29194    381.1141          0      85000
    incaloth |  6,076,183    23.06841    435.2779          0      93600
    incretir |  6,076,183    594.8235    3980.603          0     223998
      incssi |  6,076,183    73.75355     741.366          0      25000
-------------+---------------------------------------------------------
      incdrt |  6,076,183    45.37569    870.3989      -9990      96050
      incint |  6,076,183    503.5771    3013.785          0      99759
    incunemp |  6,076,183    82.30337    903.4856          0      98800
    incwkcom |  6,076,183    29.71038    697.8221          0      99961
      incvet |  6,076,183    60.09821    1119.068          0      98411
-------------+---------------------------------------------------------
     incsurv |  6,076,183    71.69611    1509.675          0     296138
    incdisab |  6,076,183    44.41491    999.1403          0     146968
    incdivid |  6,076,183    207.5637    2079.057          0     100000
     incrent |  6,076,183     141.414    2166.293      -9960      99360
     inceduc |  6,076,183    95.22036    1100.801          0      85000
-------------+---------------------------------------------------------
    incchild |  6,076,183    64.16382    799.3326          0      98000
     incalim |  6,076,183    11.30533    567.1272          0      96000
    incasist |  6,076,183    29.83736     748.831          0      96000
    incother |  6,076,183    23.22233    652.0811          0      99600

. save WorkingFullCPSTEMP, replace ;
file WorkingFullCPSTEMP.dta saved

. capture erase `cps'.do ;

. capture erase `cps'.dat ;

. capture erase `cps'.dat.gz ;

. clear ;

. ***************************************************************************;
. * BUILDING CHILDREN ;
. ***************************************************************************;
. local generationvars "age sex schlcoll marst whynwly wtsupp `income_vars'" ;

.  * YOUNGEST GENERATION CHILD FILE ;
. use WorkingFullCPSTEMP ;

. keep year serial pernum momloc poploc `generationvars' ;

. foreach var of varlist pernum momloc poploc `generationvars'  {;
  2.         rename `var' `var'G0 ;
  3.         };

. gen pernum = momlocG0 ;

. replace pernum = poplocG0 if momlocG0==0 & poplocG0>0 ;
(104,938 real changes made)

. drop if pernum == 0 ;
(3,890,213 observations deleted)

. save childrens, replace ;
(note: file childrens.dta not found)
file childrens.dta saved

. clear ;

. foreach gen in 1 2 3 4 5 {;
  2.         use WorkingFullCPSTEMP ;
  3.         keep year serial pernum momloc poploc `generationvars' ;
  4.         foreach var of varlist momloc poploc `generationvars' {;
  5.                 rename `var' `var'G`gen' ;
  6.                 };
  7.         sort year serial pernum ;
  8.         merge 1:m year serial pernum using childrens ;
  9.         drop if _merge == 1 ;
 10.         drop _merge ;
 11.         rm childrens.dta ;
 12.         rename pernum pernumG`gen' ;
 13.         gen pernum = momlocG`gen' ;
 14.         replace pernum = poplocG`gen' if momlocG`gen'==0 ;
 15.         count if pernum >0 & pernum!=. ;
 16.         * BREAK LOOK IF WE CANNOT FIND ANY NEW PARENTS ;
.         if r(N)==0 {;
 17.                 continue, break ;
 18.                 };
 19.         sort year serial pernum ;
 20.         save childrens, replace ;
 21.         clear ;
 22.         };
(note: variable pernum was byte, now float to accommodate using data's values)
(label incdivid_lbl already defined)
(label incfarm_lbl already defined)
(label incbus_lbl already defined)
(label incwage_lbl already defined)
(label inctot_lbl already defined)
(label whynwly_lbl already defined)
(label schlcoll_lbl already defined)
(label marst_lbl already defined)
(label sex_lbl already defined)
(label age_lbl already defined)
(label wtsupp_lbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     4,909,420
        from master                 4,909,420  (_merge==1)
        from using                          0  (_merge==2)

    matched                         2,185,970  (_merge==3)
    -----------------------------------------
(4,909,420 observations deleted)
(7,204 real changes made)
  76,608
(note: file childrens.dta not found)
file childrens.dta saved
(note: variable pernum was byte, now float to accommodate using data's values)
(label incdivid_lbl already defined)
(label incfarm_lbl already defined)
(label incbus_lbl already defined)
(label incwage_lbl already defined)
(label inctot_lbl already defined)
(label whynwly_lbl already defined)
(label schlcoll_lbl already defined)
(label marst_lbl already defined)
(label sex_lbl already defined)
(label age_lbl already defined)
(label wtsupp_lbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     8,136,723
        from master                 6,027,361  (_merge==1)
        from using                  2,109,362  (_merge==2)

    matched                            76,608  (_merge==3)
    -----------------------------------------
(6,027,361 observations deleted)
(2,109,362 missing values generated)
(125 real changes made)
  765
(note: file childrens.dta not found)
file childrens.dta saved
(note: variable pernum was byte, now float to accommodate using data's values)
(label wtsupp_lbl already defined)
(label age_lbl already defined)
(label sex_lbl already defined)
(label marst_lbl already defined)
(label schlcoll_lbl already defined)
(label whynwly_lbl already defined)
(label inctot_lbl already defined)
(label incwage_lbl already defined)
(label incbus_lbl already defined)
(label incfarm_lbl already defined)
(label incdivid_lbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     8,260,891
        from master                 6,075,686  (_merge==1)
        from using                  2,185,205  (_merge==2)

    matched                               765  (_merge==3)
    -----------------------------------------
(6,075,686 observations deleted)
(2,185,205 missing values generated)
(0 real changes made)
  0

. gen generation = .;
(2,185,970 missing values generated)

. replace generation = 1 if ageG1!=. & momlocG0!=. & momlocG0>0 & sexG1==2 & (ageG1>=24&ageG1<=48) ;
(1,650,380 real changes made)

. replace generation = 2 if ageG2!=. & momlocG1!=. & momlocG1>0 & sexG2==2 & (ageG2>=24&ageG2<=48) & generation==.;
(10,570 real changes made)

. replace generation = 3 if ageG3!=. & momlocG2!=. & momlocG2>0 & sexG3==2 & (ageG3>=24&ageG3<=48) & generation==.;
(2 real changes made)

. tab generation ;

 generation |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |  1,650,380       99.36       99.36
          2 |     10,570        0.64      100.00
          3 |          2        0.00      100.00
------------+-----------------------------------
      Total |  1,660,952      100.00

. * PERNUM WILL BE HOW WE MERGE CHILD TO MOM ;
. drop pernum ;

. gen pernum = . ;
(2,185,970 missing values generated)

. replace pernum = momlocG0 if generation==1 ;
(1,650,380 real changes made)

. replace pernum = momlocG1 if generation==2 ;
(10,570 real changes made)

. replace pernum = momlocG2 if generation==3 ;
(2 real changes made)

. drop if pernum == . ;
(525,018 observations deleted)

. * FINALLY THE CHILD DEMOS WE WANT TO BRINK ALONG ;
. foreach var in `generationvars' {;
  2.         rename `var'G0 `var' ;
  3.         };

. keep year serial pernum `generationvars' ;

. gen qualChild = 1 if (age<=18 | (age>18 & age<24 & (schlcoll==1|schlcoll==3))) ;
(102,376 missing values generated)

. * NUMBER OF CHILDREN BY AGE ;
. local agelow  "0 0 6  15";

. local agehigh "1 5 14 24";

. foreach i of numlist 1(1)4 {;
  2.         local al : word `i' of `agelow' ;
  3.         local ah : word `i' of `agehigh' ;
  4.         gen childAgeBin_`al'_`ah' = (age>=`al' & age<=`ah' & qualChild==1);
  5.         };

. summ childAgeBin_* ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
childAgeBi~1 |  1,660,952    .0808837    .2726566          0          1
childAgeBi~5 |  1,660,952    .2766167    .4473254          0          1
childAgeB~14 |  1,660,952    .4660496    .4988462          0          1
childAgeB~24 |  1,660,952    .1956968    .3967363          0          1

. * WE NEED THE WEIGHTS FROM CHILDREN TO CONSTRUCT INDIVIDUAL ESTIMATES OF POVERTY ;
. rename wtsupp chldwt ;

. * INCOME VARIABLES FOR CHILDREN. SUMMATION ACROSS K ;
. gen temp = 0 ;

. foreach var of varlist `income_vars' {;
  2.         if "`var'" != "inctot" {;
  3.                 qui replace temp = temp + `var' ;
  4.                 local name = substr("`var'",4,.) ;
  5.                 rename `var' chld`name' ;
  6.                 local chldinc_vars "`chldinc_vars' chld`name'";
  7.                 local name ;
  8.                 };
  9.         };

. rename temp chldtot ;

. drop inctot ;

. local chldinc_vars "`chldinc_vars' chldtot";

. summ `chldinc_vars' ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    chldwage |  1,660,952    811.6757    4119.246          0     688117
     chldbus |  1,660,952    13.34519    761.4478     -12999     446853
    chldfarm |  1,660,952    2.894766    528.2446      -8000     360886
      chldss |  1,660,952    31.80551    493.2394          0      50000
   chldwelfr |  1,660,952    6.799595    171.9798          0      25000
-------------+---------------------------------------------------------
     chldgov |  1,660,952    2.095076    92.97253          0      29999
   chldaloth |  1,660,952    7.993825    199.7564          0      75000
   chldretir |  1,660,952    .5692874    107.0726          0      60000
     chldssi |  1,660,952    12.66675    282.2332          0      25000
     chlddrt |  1,660,952    1.318408    108.7902      -7200      50000
-------------+---------------------------------------------------------
     chldint |  1,660,952     17.7284    413.4564          0      85606
   chldunemp |  1,660,952    4.390279    170.9987          0      31136
   chldwkcom |  1,660,952    .9525953     120.327          0      99961
     chldvet |  1,660,952    .5198356    91.20448          0      90000
    chldsurv |  1,660,952    2.018667    238.4102          0      89702
-------------+---------------------------------------------------------
   chlddisab |  1,660,952    1.803522      174.85          0      75000
   chlddivid |  1,660,952    4.489808    239.3402          0      75000
    chldrent |  1,660,952    1.984939    234.5343      -7500      87000
    chldeduc |  1,660,952    66.20193    874.3331          0      80000
   chldchild |  1,660,952    5.747836    193.6042          0      41000
-------------+---------------------------------------------------------
    chldalim |  1,660,952    .0541515    18.47116          0      16000
   chldasist |  1,660,952    1.126379    136.6976          0      60846
   chldother |  1,660,952    2.361277    96.24631          0      51238
     chldtot |  1,660,952    1000.544    4585.394      -9079     740987

. sort year serial pernum ;

. collapse (sum) qualChild childAgeBin_* chldwt `chldinc_vars', by(year serial pernum) ;

. replace year = year -1 ;
(796,863 real changes made)

. foreach var of varlist childAgeBin_* {;
  2.         replace `var' = 1 if `var' >1 ;
  3.         };
(6,079 real changes made)
(105,559 real changes made)
(216,614 real changes made)
(66,950 real changes made)

. sort year serial pernum ;

. save childrensFAMILY, replace ;
(note: file childrensFAMILY.dta not found)
file childrensFAMILY.dta saved

. clear ;

. ***************************************************************************;
. * NOW LETS CONSTRUCT OUR SAMPLE OF WOMEN. ;
. ***************************************************************************;
. use WorkingFullCPSTEMP ;

. keep `technical_vars' `demographic_vars' `income_vars' ;

. sort year serial famunit;

. * HOUSEHOLD SIZE - TOTAL ;
. by year serial: gen byte hhsize = _N ;

. summ hhsize ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      hhsize |  6,076,183     3.54488    1.709528          1         26

. * FAMILY SIZE ;
. by year serial famunit: gen byte famsize = _N ;

. summ famsize ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
     famsize |  6,076,183    3.392119    1.737631          1         25

. tab hhsize famsize if hhsize<=10 & famsize<=10 ;

           |                                                    famsize
    hhsize |         1          2          3          4          5          6          7          8          9         10 |     Total
-----------+--------------------------------------------------------------------------------------------------------------+----------
         1 |   526,311          0          0          0          0          0          0          0          0          0 |   526,311 
         2 |   174,172  1,203,158          0          0          0          0          0          0          0          0 | 1,377,330 
         3 |    62,807     60,040  1,063,269          0          0          0          0          0          0          0 | 1,186,116 
         4 |    37,078     11,150     57,096  1,368,164          0          0          0          0          0          0 | 1,473,488 
         5 |    18,678      4,502      7,965     37,940    777,710          0          0          0          0          0 |   846,795 
         6 |     9,606      1,812      3,156      4,796     20,350    334,302          0          0          0          0 |   374,022 
         7 |     4,825        624      1,215      1,668      2,660      9,882    133,336          0          0          0 |   154,210 
         8 |     2,331        268        483        828        910      1,248      4,564     58,720          0          0 |    69,352 
         9 |     1,139        108        168        240        380        300        693      2,264     27,558          0 |    32,850 
        10 |       839         60         78         76        150        150        252        400      1,395     13,690 |    17,090 
-----------+--------------------------------------------------------------------------------------------------------------+----------
     Total |   837,786  1,281,722  1,133,430  1,413,712    802,160    345,882    138,845     61,384     28,953     13,690 | 6,057,564 


. * FAMILY KIDS ;
. gen temp = (age<=18 | (age>18 & age<24 & (schlcoll==1|schlcoll==3))) ;

. by year serial famunit: egen byte famkids = total(temp) ;

. drop temp ;

. summ famkids ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
     famkids |  6,076,183    1.407087    1.434004          0         18

. foreach r in 201 501 701 1001 1113 1114 1115 1241 1260 {;
  2.         gen relate_`r' = relate==`r' ;
  3.         } ;

. foreach var of varlist relate_* {;
  2.         by year serial : egen temp = total(`var') ;
  3.         replace `var' = temp ;
  4.         drop temp ;
  5.         };
(2,904,086 real changes made)
(125,861 real changes made)
(113,725 real changes made)
(359,259 real changes made)
(27,375 real changes made)
(129,862 real changes made)
(73,062 real changes made)
(19,794 real changes made)
(174,440 real changes made)

. gen temp = 0 ;

. foreach var of varlist `income_vars' {;
  2.         if "`var'" != "inctot" {;
  3.                 qui replace temp = temp + `var' ;
  4.                 };
  5.         };

. by year serial famunit : egen faminc = total(temp) ;

. drop temp ;

. *summ famunit `faminc_vars' ;
. * EMPLOYED - NOTE THAT THIS IS INDIVIDUAL SPECIFIC. ;
. gen byte employed = incwage > 0 & incwage != .;

. *tab employed ;
. * SEX ;
. gen byte female = sex==2 ;

. *tab year female ;
. * CREATE UNIFORM EDUCATION BINS ;
. gen byte hgc = . ;
(6,076,183 missing values generated)

. replace hgc = 11 if floor(educ/10) < 7;
(2,539,460 real changes made)

. replace hgc = 12 if floor(educ/10) == 7;
(1,527,290 real changes made)

. replace hgc = 13 if floor(educ/10) > 7 & floor(educ/10) < 11;
(1,050,615 real changes made)

. replace hgc = 16 if floor(educ/10) == 11;
(621,007 real changes made)

. replace hgc = 17 if floor(educ/10) >= 12 & floor(educ/10) < 90 ;
(337,811 real changes made)

. *tab year hgc , missing;
. * TAX YEAR ;
. replace year = year - 1;
(6,076,183 real changes made)

. * ------------- RESTRICTIONS --------------- ;
. * KEEP IF FEMALE ;
. keep if female == 1 ;
(2,938,334 observations deleted)

. count ;
  3,137,849

. * KEEP IF UNMARRIED ;
. drop if marst == 1 | marst == 2 ;
(1,294,863 observations deleted)

. count ;
  1,842,986

. * AGE RESTRICTION - NEED THIS TO BE HIGHER THAN QUAL AGE;
. keep if age >= 24 & age <= 48 ;
(1,449,786 observations deleted)

. count ;
  393,200

. * DROP IF THE REASON DIDNT WORK LAST YEAR WAS SICKNESS, DISABILITY, 
> *       GOING TO SCHOOL ;
. drop if whynwly==2 | whynwly==4 ;
(31,260 observations deleted)

. count ;
  361,940

. * ------------- RESTRICTIONS --------------- ;
. * FAMILY SPECIFIC CHILDREN ;
. sort year serial pernum ;

. merge 1:1 year serial pernum using childrensFAMILY ;
(note: variable pernum was byte, now float to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                       812,573
        from master                   188,825  (_merge==1)
        from using                    623,748  (_merge==2)

    matched                           173,115  (_merge==3)
    -----------------------------------------

. drop if _merge ==2 ;
(623,748 observations deleted)

. drop _merge ;

. foreach var of varlist qualChild childAgeBin_* {;
  2.         replace `var' = 0 if `var' == . ;
  3.         };
(188,825 real changes made)
(188,825 real changes made)
(188,825 real changes made)
(188,825 real changes made)
(188,825 real changes made)

. summ qualChild childAgeBin_* ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
   qualChild |    361,940    .8503039    1.156626          0         12
childAgeBi~1 |    361,940    .0502127     .218384          0          1
childAgeBi~5 |    361,940    .1659584    .3720438          0          1
childAgeB~14 |    361,940    .3006106    .4585242          0          1
childAgeB~24 |    361,940    .1505857    .3576451          0          1

. capture rm childrensFAMILY.dta ;

. capture rm childrensHOUSEHOLD.dta ;

. local i = 1 ;

. foreach var of varlist `income_vars' {;
  2.         local name = substr("`var'",4,.) ;
  3.         egen fam`name' = rowtotal(`var' chld`name') ;
  4.         local faminc_vars "`faminc_vars' fam`name'";
  5.         local name ;
  6.         };

. summ `faminc_vars' ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      famtot |    361,940    24496.48    26231.33     -16999    1000000
     famwage |    361,940     21103.4    24612.65          0    1000000
      fambus |    361,940    592.2581    5832.957     -18000     502982
     famfarm |    361,940     36.2433    2691.135     -14000     500000
       famss |    361,940     289.752    1977.434          0      69360
-------------+---------------------------------------------------------
    famwelfr |    361,940    305.3184    1259.177          0      44240
      famgov |    361,940    26.10761     332.963          0      29999
    famaloth |    361,940    108.8097    921.8331          0      93600
    famretir |    361,940    43.44521    927.2709          0      84000
      famssi |    361,940    98.32044    865.2679          0      49000
-------------+---------------------------------------------------------
      famdrt |    361,940    26.94716     680.645      -9000      65100
      famint |    361,940    267.9698    1962.408          0     109968
    famunemp |    361,940    162.3371    1211.578          0      93500
    famwkcom |    361,940    25.02888    545.0117          0      69544
      famvet |    361,940    16.05856    478.0201          0      57024
-------------+---------------------------------------------------------
     famsurv |    361,940    63.08654    1666.708          0     199998
    famdisab |    361,940    20.95776    583.5297          0      59407
    famdivid |    361,940    97.78482    1230.914          0     100000
     famrent |    361,940    90.03525    1721.855      -9700     219531
     fameduc |    361,940    262.1987    1784.938          0      87000
-------------+---------------------------------------------------------
    famchild |    361,940    618.4936    2450.813          0      92000
     famalim |    361,940    67.36353    1336.915          0      91800
    famasist |    361,940    76.98726    1142.952          0      84000
    famother |    361,940    34.87456    666.8065          0      65537

. ***************************************************************************;
. * RUN THROUGH TAXSIM ;
. ***************************************************************************;
. * STATE ;
. gen byte state = . ;
(361,940 missing values generated)

. replace state = statefip   if statefip <= 2 ;
(8,982 real changes made)

. replace state = statefip-1 if statefip >= 4  & statefip <= 6 ;
(44,440 real changes made)

. replace state = statefip-2 if statefip >= 8  & statefip <= 13 ;
(47,751 real changes made)

. replace state = statefip-3 if statefip >= 15 & statefip <= 42 ;
(192,423 real changes made)

. replace state = statefip-4 if statefip >= 44 & statefip <= 51 ;
(51,200 real changes made)

. replace state = statefip-5 if statefip >= 53 & statefip <= 56 ;
(17,144 real changes made)

. *tab state, missing ;
. gen byte depx = min(qualChild, 5) ;

. gen byte depchild = depx ;

. gen byte mstat = 1 ;

. gen pwages = max(incwage+incbus+incfarm,0) ;

. gen byte swages = 0 ;

. gen byte dividends = 0 ;

. gen byte agex=0 ;

. gen gssi = incss+incssi+incsurv+incdisab;

. gen pensions = incretir;

. gen ui = incunemp;

. gen otherprop = min(incwage+incbus+incfarm,0) +  
>         incaloth + incalim + incother + incdrt + incint + incdivid + incrent ;

. gen transfers = incwelfr+incgov+incwkcom+incvet+inceduc+incchild+incasist;

. sort year serial ;

. save cpsBeforeTaxsim, replace ;
file cpsBeforeTaxsim.dta saved

. keep year serial pernum state agex depx depchild mstat 
>         pwages swages dividends gssi pensions ui otherprop transfers;

. capture rm msg.txt;

. capture rm taxsim_out.dta;

. ankurs_taxsim, full replace;
begin taxsim9.ado on 13 Apr 2018 (version 9.0)
TAXSIM results will be merged to original file
TAXSIM results will be saved in taxsim_out.dta
Full Intermediate Calculations Requested
Marginal rate with respect to primary earner
Variable rentpaid is not in the dataset.  Generating rentpaid = 0 
Variable proptax is not in the dataset.  Generating proptax = 0 
Variable otheritem is not in the dataset.  Generating otheritem = 0 
Variable childcare is not in the dataset.  Generating childcare = 0 
Variable mortgage is not in the dataset.  Generating mortgage = 0 
Variable stcg is not in the dataset.  Generating stcg = 0 
Variable ltcg is not in the dataset.  Generating ltcg = 0 
361940 records out of 361940 are left for taxsim to process
 
TAXSIM results are being merged with workspace by taxsimid
(note: variable year was int, now float to accommodate using data's values)
(note: variable state was byte, now float to accommodate using data's values)
 

. capture rm msg.txt;

. capture rm taxsim_out.dta;

. keep year serial pernum fiitax fica siitax v25 v39 v22 v23 v19 ;

. rename v25 fedEIC;

. rename v39 stEIC ;

.   rename v22 ctc ;

. rename v23 actc ;

. rename v19 fedRegTax ;

. sort year serial pernum ;

. save CYtaxsim, replace ;
(note: file CYtaxsim.dta not found)
file CYtaxsim.dta saved

. clear ;

. use cpsBeforeTaxsim ;

. keep year serial pernum state agex depx depchild mstat 
>         pwages swages dividends gssi pensions ui otherprop transfers;

. sort year;

. merge year using cpi;
(note: you are using old merge syntax; see [D] merge for new syntax)
variable year does not uniquely identify observations in the master data

. keep if _merge == 3 ;
(66 observations deleted)

. drop _merge ;

. rename cpi currentYearCpi ;

. replace year = year - 1 ;
(361,940 real changes made)

. sort year;

. merge year using cpi;
(note: you are using old merge syntax; see [D] merge for new syntax)
variable year does not uniquely identify observations in the master data

. keep if _merge == 3 ;
(66 observations deleted)

. drop _merge ;

. rename cpi priorYearCpi ;

. foreach dollar of varlist pwages swages gssi 
>                 otherprop pensions transfers ui {;
  2.         replace `dollar' = `dollar' * (priorYearCpi/currentYearCpi);
  3.         };
(318,638 real changes made)
(0 real changes made)
(17,296 real changes made)
(151,007 real changes made)
(2,455 real changes made)
(97,506 real changes made)
(15,441 real changes made)

. capture rm msg.txt;

. capture rm taxsim_out.dta;

. ankurs_taxsim, full replace;
begin taxsim9.ado on 13 Apr 2018 (version 9.0)
TAXSIM results will be merged to original file
TAXSIM results will be saved in taxsim_out.dta
Full Intermediate Calculations Requested
Marginal rate with respect to primary earner
Variable rentpaid is not in the dataset.  Generating rentpaid = 0 
Variable proptax is not in the dataset.  Generating proptax = 0 
Variable otheritem is not in the dataset.  Generating otheritem = 0 
Variable childcare is not in the dataset.  Generating childcare = 0 
Variable mortgage is not in the dataset.  Generating mortgage = 0 
Variable stcg is not in the dataset.  Generating stcg = 0 
Variable ltcg is not in the dataset.  Generating ltcg = 0 
361940 records out of 361940 are left for taxsim to process
 
TAXSIM results are being merged with workspace by taxsimid
(note: variable year was int, now float to accommodate using data's values)
(note: variable state was byte, now float to accommodate using data's values)
 

. capture rm msg.txt;

.  capture rm taxsim_out.dta;

. keep year serial pernum v25 v39 v22 v23 v19 priorYearCpi currentYearCpi ;

. rename v25 fedEIC_ly;

. rename v39 stEIC_ly;

.   rename v22 ctc_ly;

. rename v23 actc_ly;

. rename v19 fedRegTax_ly ;

. foreach dollar of varlist fedEIC_ly stEIC_ly ctc_ly actc_ly fedRegTax_ly {;
  2.         replace `dollar' = `dollar' * (currentYearCpi/priorYearCpi);
  3.         };
(110,828 real changes made)
(24,836 real changes made)
(53,599 real changes made)
(25,745 real changes made)
(261,015 real changes made)

. drop priorYearCpi currentYearCpi ;

. replace year = year + 1 ;
(361,940 real changes made)

. sort year serial pernum;

. save LYtaxsim, replace ;
(note: file LYtaxsim.dta not found)
file LYtaxsim.dta saved

. clear ;

. use cpsBeforeTaxsim ;

. merge 1:1 year serial pernum using CYtaxsim ;
(note: variable year was int, now float to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           361,940  (_merge==3)
    -----------------------------------------

. drop _merge ;

. merge 1:1 year serial pernum using LYtaxsim ;

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           361,940  (_merge==3)
    -----------------------------------------

. drop _merge ;

. drop depx depchild mstat pwages swages dividends gssi pensions ui 
>         otherprop transfers;

. *rm cpsBeforeTaxsim.dta ;
. rm CYtaxsim.dta ;

. rm LYtaxsim.dta ;

. local taxsim_output "fiitax fica siitax fedEIC stEIC ctc actc fedRegTax 
>         fedEIC_ly stEIC_ly ctc_ly actc_ly fedRegTax_ly" ;

.         ***************************************************************************;
. * INFLATION  ;
. ***************************************************************************;
. sort year;

. merge year using cpi;
(note: you are using old merge syntax; see [D] merge for new syntax)
variable year does not uniquely identify observations in the master data

. tab _merge;

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          2 |         66        0.02        0.02
          3 |    361,940       99.98      100.00
------------+-----------------------------------
      Total |    362,006      100.00

. keep if _merge == 3 ;
(66 observations deleted)

. drop _merge ;

. foreach dollar of varlist `income_vars' `taxsim_output' 
>                 stampval heatval `faminc_vars' `chldinc_vars' faminc {;
  2.         qui replace `dollar' = `dollar' * (232.957/cpi);
  3.         };

. replace heatval = 0 if heatval==.;
(16,217 real changes made)

. replace heatval = heatval*(1+qualChild)/(hhsize) ;
(6,933 real changes made)

. replace stampval = 0 if stampval==. ;
(0 real changes made)

. replace stampval = stampval*(1+qualChild)/(hhsize) ;
(25,396 real changes made)

. gen atti = inctot+stampval+heatval-fiitax-siitax-fica ;

. summ ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        year |    361,940    1997.441    9.962079       1979       2013
      serial |    361,940    42221.65    25920.39          1      99984
     hwtsupp |    361,940    1585.676    947.4166          0   17957.53
    statefip |    361,940    27.32822    15.57938          1         56
     pubhous |    361,940    .5856993     .582639          0          2
-------------+---------------------------------------------------------
     rentsub |    361,940    .5170498    .5532038          0          2
     heatsub |    345,723    1.056791    .2314434          1          2
     heatval |    361,940    21.09921    121.3642          0     6667.8
    foodstmp |    361,940    1.168511    .3743203          1          2
    stampval |    361,940    451.2972    1360.762          0    27145.4
-------------+---------------------------------------------------------
    lunchsub |    361,940    .4914157    .7340631          0          2
       nfams |    361,940    1.323335    .6244921          0         15
    nmothers |    361,940    .6864867    .6163941          0          5
      pernum |    361,940    1.630273    1.112679          1         21
      spmpov |     51,159    .1938271    .3952989          0          1
-------------+---------------------------------------------------------
       spmwt |     51,159     1523.58     942.076      97.32    8761.64
 spmfedtaxac |     51,159    3871.356    14503.15     -17449     681967
     spmeitc |     51,159    1034.052    1695.197          0      11999
 spmfedtaxbc |     51,159    5475.182    13940.37          0     681967
   spmtotres |     51,159    44443.82    39956.15    -181979    1142270
-------------+---------------------------------------------------------
   spmthresh |     51,159    21142.96    8533.702    7790.45    87084.3
      wtsupp |    361,940    1595.162    954.0286          0   12604.76
      momloc |    361,940    .2671354    .7273823          0         13
     momrule |    361,940    .1537824      .36433          0          7
      poploc |    361,940    .1400232    .5240102          0         14
-------------+---------------------------------------------------------
     poprule |    361,940    .1020307     .328607          0          7
     famunit |    361,940    1.157333    .4128063          1         10
      relate |    361,940    316.3492    384.1925        101       1260
         age |    361,940     34.4756    7.305641         24         48
         sex |    361,940           2           0          2          2
-------------+---------------------------------------------------------
        race |    361,940    152.3037    132.8358        100        830
       marst |    361,940    4.990766    1.132036          3          6
      hispan |    361,940    38.51772    115.8629          0        902
        educ |    361,940    83.00084    23.44224          2        125
    schlcoll |    312,324    .5965696    1.591148          0          5
-------------+---------------------------------------------------------
    wkswork1 |    361,940    40.95828    18.64891          0         52
    uhrswork |    361,940    34.26002    15.49644          0         99
    wksunem1 |    361,940    78.42468    38.36967          0         99
       union |    276,242    .1855113    .4526648          0          3
     whynwly |    361,940     .346947    1.046833          0          7
-------------+---------------------------------------------------------
      inctot |    361,940    33259.78    31803.52  -27922.03    1000000
     incwage |    361,940    28637.78    29955.89          0    1000000
      incbus |    361,940    814.4931    7626.174  -29018.87   620292.1
     incfarm |    361,940    46.36033    3419.918  -17724.99   567390.4
       incss |    361,940    335.8727    2419.543          0   76429.47
-------------+---------------------------------------------------------
    incwelfr |    361,940    523.7738     2197.57          0   57757.94
      incgov |    361,940    58.97421    766.2276          0   84811.61
    incaloth |    361,940     244.024    2122.657          0   202646.6
    incretir |    361,940    65.30647     1339.82          0   175419.4
      incssi |    361,940    104.0321    983.5849          0   37118.71
-------------+---------------------------------------------------------
      incdrt |    361,940    63.39026    1617.332  -23663.23   160438.7
      incint |    361,940    391.9634    2740.319          0   190580.8
    incunemp |    361,940    194.4832     1409.05          0   111356.1
    incwkcom |    361,940    33.22145    751.5551          0   142612.3
      incvet |    361,940    20.26156     595.234          0   72196.41
-------------+---------------------------------------------------------
     incsurv |    361,940    80.73447    2225.171          0   410131.5
    incdisab |    361,940    24.68841    723.3927          0   98460.27
    incdivid |    361,940     126.486    1602.298          0   131458.7
     incrent |    361,940    116.7896    2148.672  -17722.85   154767.3
     inceduc |    361,940    255.5948    1929.728          0   132833.6
-------------+---------------------------------------------------------
    incchild |    361,940    785.5816    3095.151          0   188252.2
     incalim |    361,940    90.74128    1751.357          0   188252.2
    incasist |    361,940    99.68049    1479.065          0   112851.1
    incother |    361,940    43.93426    853.9874          0   80822.15
    mthwelfr |    294,154    .6597701    2.614288          0         12
-------------+---------------------------------------------------------
      offpov |    361,940    1.780856     .413667          1          2
   offtotval |    361,940    33968.57    39031.17     -19998    1234401
   offcutoff |    361,940    12377.38    5802.207       3076      51154
     poverty |    361,940    19.94146    5.334812         10         23
    qincwage |    361,940     .042286    .2256661          0          3
-------------+---------------------------------------------------------
      hhsize |    361,940    2.932527    1.631953          1         26
     famsize |    361,940    2.509118    1.635575          1         25
     famkids |    361,940    .9960767    1.255706          0         14
  relate_201 |    361,940    .0990827    .2987735          0          1
  relate_501 |    361,940    .0431563    .2271189          0          2
-------------+---------------------------------------------------------
  relate_701 |    361,940    .0568713    .2951293          0         10
 relate_1001 |    361,940    .1297729    .5504219          0         14
 relate_1113 |    361,940     .031729    .1956146          0          7
 relate_1114 |    361,940    .1133751    .3172516          0          3
 relate_1115 |    361,940    .0674615    .3513798          0         12
-------------+---------------------------------------------------------
 relate_1241 |    361,940    .0118666    .1496534          0         10
 relate_1260 |    361,940     .139863    .5239159          0         16
      faminc |    361,940    47867.72    47706.62  -28529.21    1172464
    employed |    361,940    .8572968    .3497704          0          1
      female |    361,940           1           0          1          1
-------------+---------------------------------------------------------
         hgc |    361,940    13.25494    1.901225         11         17
   qualChild |    361,940    .8503039    1.156626          0         12
childAgeBi~1 |    361,940    .0502127     .218384          0          1
childAgeBi~5 |    361,940    .1659584    .3720438          0          1
childAgeB~14 |    361,940    .3006106    .4585242          0          1
-------------+---------------------------------------------------------
childAgeB~24 |    361,940    .1505857    .3576451          0          1
      chldwt |    173,115    2852.301    2445.934          0   40977.49
    chldwage |    173,115    2425.749    9147.551          0     804586
     chldbus |    173,115    34.42302    1424.556  -18176.52   250740.2
    chldfarm |    173,115    4.086293      827.74  -10479.03   258112.2
-------------+---------------------------------------------------------
      chldss |    173,115    208.5434    1627.481          0   74237.42
   chldwelfr |    173,115    54.05949    653.5362          0   39297.74
     chldgov |    173,115    10.71743    303.4997          0   32916.48
   chldaloth |    173,115    44.98172    808.3577          0   112106.4
   chldretir |    173,115    3.375068    284.0487          0   56960.49
-------------+---------------------------------------------------------
     chldssi |    173,115      67.299    783.2655          0   40078.62
     chlddrt |    173,115    3.971362    275.2251  -4210.066   58071.09
     chldint |    173,115    35.84703    778.4727          0   130908.4
   chldunemp |    173,115    14.62836    348.0486          0    33010.1
   chldwkcom |    173,115    3.472016    211.3742          0   43434.37
-------------+---------------------------------------------------------
     chldvet |    173,115    2.623789    140.7679          0   16895.78
    chldsurv |    173,115    11.25327    591.5359          0   98124.93
   chlddisab |    173,115    7.923538    406.1218          0   62876.38
   chlddivid |    173,115     7.12777    363.2227          0   62876.38
    chldrent |    173,115    7.484513    761.7768  -8708.673   158354.5
-------------+---------------------------------------------------------
    chldeduc |    173,115    168.4514    1592.282          0      87000
   chldchild |    173,115    35.79755    613.2402          0   70853.43
    chldalim |    173,115    .3242695    56.24521          0   16976.62
   chldasist |    173,115    4.466588    246.5596          0   27514.61
   chldother |    173,115    6.983907    237.6205          0   53703.48
-------------+---------------------------------------------------------
     chldtot |    173,115    3163.589    10422.59  -5429.297   871382.7
      famtot |    361,940    34772.91    32781.46  -27922.03    1000000
     famwage |    361,940    29798.01    30726.01          0    1000000
      fambus |    361,940    830.9576    7700.666  -29018.87   620292.1
     famfarm |    361,940    48.31479    3467.472  -17724.99   567390.4
-------------+---------------------------------------------------------
       famss |    361,940    435.6185    2826.369          0   76429.47
    famwelfr |    361,940    549.6304     2275.53          0   57757.93
      famgov |    361,940    64.10033    812.0781          0   84811.61
    famaloth |    361,940    265.5386    2231.604          0   202646.6
    famretir |    361,940    66.92076     1360.25          0   175419.4
-------------+---------------------------------------------------------
      famssi |    361,940    136.2211    1148.436          0   53207.11
      famdrt |    361,940    65.28975    1644.267  -23663.23   164449.7
      famint |    361,940    409.1089    2816.323          0     195065
    famunemp |    361,940    201.4799    1433.366          0   111356.1
    famwkcom |    361,940    34.88211    765.6462          0   142612.3
-------------+---------------------------------------------------------
      famvet |    361,940    21.51651    611.0033          0   72196.41
     famsurv |    361,940    86.11688    2270.608          0   410131.5
    famdisab |    361,940    28.47822    776.1743          0   98460.27
    famdivid |    361,940    129.8952     1624.26          0   131458.7
     famrent |    361,940    120.3695    2228.501  -17722.85   237531.7
-------------+---------------------------------------------------------
     fameduc |    361,940    336.1647    2224.829          0   132833.6
    famchild |    361,940    802.7035    3125.447          0   188252.2
     famalim |    361,940    90.89638    1752.104          0   188252.2
    famasist |    361,940    101.8168    1492.189          0   112851.1
    famother |    361,940    47.27465    877.1777          0   80822.15
-------------+---------------------------------------------------------
       state |    361,940    24.54397    14.63426          1         51
        agex |    361,940           0           0          0          0
      fiitax |    361,940    2965.121    8185.403  -8756.369     339339
      siitax |    361,940    883.6418     1823.79  -2613.392   64178.73
        fica |    361,940     4246.11     3651.89          0    50298.8
-------------+---------------------------------------------------------
   fedRegTax |    361,940    3818.777    7736.451          0     339339
         ctc |    361,940     176.516    500.6617          0   6330.353
        actc |    361,940    77.14842    336.4522          0   4723.488
      fedEIC |    361,940    577.3027     1236.18          0   6142.706
       stEIC |    361,940     28.1059     158.427          0   3026.595
-------------+---------------------------------------------------------
fedRegTax_ly |    361,940    3860.315    7814.353          0   304919.8
      ctc_ly |    361,940    168.7487    489.1267          0   6330.353
     actc_ly |    361,940      67.836    314.2558          0   4665.529
   fedEIC_ly |    361,940    562.1994    1216.378          0   6142.706
    stEIC_ly |    361,940    26.29787    153.5086          0   3071.353
-------------+---------------------------------------------------------
         cpi |    361,940    162.4561    44.96084       72.6    232.957
        atti |    361,940     25637.3    19960.21  -27745.67   560750.2

. save cpsAfterTaxsim, replace ;
file cpsAfterTaxsim.dta saved

. */
> *;
. disp "`beginTime'" ;
DateTime: 13 Apr 2018 11:33:24

. disp "DateTime: $S_DATE $S_TIME";
DateTime: 13 Apr 2018 11:48:38

. log close ;
      name:  <unnamed>
       log:  1_SingleWomen_ReadInCps.log
  log type:  text
 closed on:  13 Apr 2018, 11:48:38
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
